﻿using HLVControl.Grid;
using HLVControl.Grid.Export;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RMAS
{
    public partial class frmExportExcel : Form
    {
        string sNameFile = "";
        TreeListView treeview;
        public frmExportExcel(string NameFile, TreeListView treeview)
        {
            InitializeComponent();
            this.treeview = treeview;
            this.sNameFile = NameFile;
        }

        private void frmExportExcel_Load(object sender, EventArgs e)
        {
            txtFilename.Text = sNameFile;
            txtSheetname.Text = "sheet_" + sNameFile;
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    XLExport xlExport = new XLExport();
                    xlExport.CreateGroups = cbHierarchy.Checked;
                    xlExport.ShowColumnHeaders = cbColHeaders.Checked;
                    xlExport.OpenAfterExport = cbOpenAfterExport.Checked;
                    xlExport.ExportFile(treeview, folderBrowserDialog.SelectedPath +
                        "\\" + txtFilename.Text + ".xls", txtSheetname.Text);

                    this.DialogResult = DialogResult.OK;
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    MessageBox.Show("Please uncheck 'Open file after export' if excel is not installed on your computer",
                        "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            base.Close();
        }

    }
}
